<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>部门管理</title>
<link href="<c:url value='/insdep/reset.min.css' />" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/easyui_full.css'/>" rel="stylesheet" type="text/css">
<link href="<c:url value='/insdep/icon.css'/>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<c:url value='/insdep/jquery-1.11.3.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/jquery.easyui-1.5.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/insdep/insdep-extend.min.js'/>"></script>
<link rel="stylesheet" type="text/css" href="<c:url value='/insdep/iconfont/iconfont.css' />">
<link href="<c:url value='/css/wsf-button.css'/>" rel="stylesheet" type="text/css">
</head>
<body> 
	<script type="text/javascript">
		$(function(){
			//按条件查询部门信息
			$("#searcher").linkbutton({onClick:function(){
					$("#dept_search_from").form('submit',{
						onSubmit:function(param){
							param.page='1';
							param.rows='2';
						},
						success:function(data){
					    	var resultData = $.parseJSON(data); 
							$("#dept_info_dg").datagrid('loadData',resultData);
						}
					});
				}
			});
			//分页把参数带过去
			$("#dept_info_dg").datagrid({
				onBeforeLoad:function(param){
					param.deptname = $("#deptname").val();
				}
			});
			//重置
			$("#reset").linkbutton({
				onClick:function(){
					$("#dept_search_from").form('reset');
					$("#dept_info_dg").datagrid('load');
				}
			});
			//刷新
			$("#deptinfo_refresh").linkbutton({
				onClick:function(){
					$("#dept_info_dg").datagrid('load');
				}
			});
			//新增部门
			$("#create_new_dept").linkbutton({
				onClick:function(){
					$("#create_and_edit_deptinfo_win").window({
					      width: 400,
				          height: 400,
				          title: '创建新部门',
				          iconCls: 'icon-update',
				          modal: true,//表示模式窗口
				          maximizable:false,
				          minimizable:false,
				          collapsible:false,
				          draggable: true,
				          resizable: false,
						  href:'to_CreateDept',//请求远程数据
						  onLoad : function() {
							  $('#create_dept').form('load',{
								  deptId:0,
								  deptName:null,
								  dept:null
					    		});
							  $('#superDept').combobox({    
								  url:'get_AllEasyDept',    
								  valueField:'id',    
								  textField:'text'   
								});
						  }
					});
				}
			});
			
			
		});
		//增加员工
		function add_dept_emp(index){
	    	$('#dept_info_dg').datagrid('selectRow',index);
	     	var row = $('#dept_info_dg').datagrid('getSelected');
	     	$("#add_emp_to_dept_win").window({
			      width: 400,
		          height: 400,
		          title: '新增员工',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable:false,
		          minimizable:false,
		          collapsible:false,
		          draggable: true,
		          deptid:row.deptId,
		          resizable: false,
				  href:'to_DeptAddEmp',//请求远程数据
				  onBeforeClose:function(){
					$("#dept_info_dg").datagrid('load');
					  return true;
				  }
			});
		}
		//删除部门
		function remove_dept(index){
			$("#dept_info_dg").datagrid("selectRow", index);
			var row = $("#dept_info_dg").datagrid("getSelected");
			alert(row.deptId);
			$("<form method='post'>").form({
				url:'remove_Dept',
				onSubmit:function(params){
					params.deptid=row.deptId
				},
				success:function(info){
					$("#dept_info_dg").datagrid('load');
				}
			}).submit(); 
		}
		//编辑部门
		function edit_dept_info(index){
			$("#dept_info_dg").datagrid('selectRow', index);
			var row = $("#dept_info_dg").datagrid('getSelected');
			$("#create_and_edit_deptinfo_win").window({
			      width: 400,
		          height: 400,
		          title: '创建新部门',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable:false,
		          minimizable:false,
		          collapsible:false,
		          draggable: true,
		          resizable: false,
				  href:'to_CreateDept',//请求远程数据
				  onLoad : function() {
					  $('#create_dept').form('load',{
						  deptId:row.deptId,
						  deptName:row.deptName,
						  superDept:row.superDept
			    		});
					  $('#superDept').combobox({    
						  url:'get_OtherDept',    
						  valueField:'id',    
						  textField:'text',
						  queryParams: {
								"deptid" : row.deptId
							}
						});

					  $("#superDept").combobox('setValues', [row.superDeptId,'002']);
				  }
			});
		}
		//部门详情
		function dept_desc(index){
			$("#dept_info_dg").datagrid('selectRow', index);
			var row = $("#dept_info_dg").datagrid('getSelected');
			$("#dept_details_win").window({
			      width: 500,
		          height: 600,
		          title: '部门详情',
		          iconCls: 'icon-update',
		          modal: true,//表示模式窗口
		          maximizable:false,
		          minimizable:false,
		          collapsible:false,
		          draggable: true,
		          resizable: false,
		          deptid: row.deptId,
				  href:'to_DeptDescInfo'//请求远程数据
				  
			});
		}
		//部门操作
		function dept_action(val,row,index){
			var remove = "", edit = "", addemp = "", deptdesc = "";
			remove = "<a class='button-teal iconfont icon-delete' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%'  onclick='remove_dept("+index+")'>删除</a>";
			edit = "<a class='button-teal iconfont icon-shenqingshenpi' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='edit_dept_info("+index+")'>编辑</a/>";
			addemp = "<a class='button-blue iconfont icon-friendadd' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='add_dept_emp("+index+")'>增加员工</a>";
			deptdesc = "<a class='button-darkblue iconfont icon-gonggao' style='color:white;padding:5px 7px;font-size:14px;margin-right:3%' onclick='dept_desc("+index+")'>部门详情</a>";
			return remove+edit+addemp+deptdesc;
		}
	</script>
	<div class="easyui-layout" data-options="fit:true">
	<!-- 查询表单  --> 
    <div data-options="region:'north',title:'部门管理',split:true,collapsed:true" style="padding:10px;height:100px;">
    	<form action="get_AllDept" id="dept_search_from" class="searcher-form" method="post">
			<input name="deptname" id="deptname" class="easyui-textbox field" label="部门名称："  labelWidth="70" style="width:300px">
    		<a id="searcher" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-search'">检索</a>
			<a id="reset" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-reload'">重置</a>
    	</form>
    </div> 
    <!-- 数据表格  --> 
    <div data-options="region:'center',border:false" style="border-top: 1px solid #D3D3D3">
		<table id="dept_info_dg" class="easyui-datagrid" 
		data-options="
		fit:true,
		url:'get_AllDept',
		rownumbers: true,
		toolbar: '#tb',
		nowrap:false, 
		autoRowHeight:false,
		pagination:true,
		pageSize: 2,
		pageList:[2,4,6,8]">
		<thead>
			<tr>
				<th style="width:10%;" data-options="field:'deptId', align:'center',sortable:true">部门编号</th>
				<th style="width:20%;" data-options="field:'deptName', align:'center'">部门名称</th>
				<th style="width:10%;" data-options="field:'empNumber', align:'center'">员工人数</th>
				<th style="width:10%;" data-options="field:'posNumber', align:'center'">职位数量</th>
				<th style="width:10%;" data-options="field:'superDeptId', align:'center',hidden:true">上级部门编号</th>
				<th style="width:20%;" data-options="field:'superDept', align:'center'">上级部门</th>
				<th data-options="field:'aaa', align:'center', formatter:dept_action,width:'31.7%'">操作</th>
			</tr>
		</thead>
		</table>
    </div>
    </div> 
    
    
    
    <!--easyui-datagrid当中的工具栏  -->
    <div id="tb">
    		<a id="create_new_dept" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-add'">创建</a>
    		<a id="deptinfo_refresh" class="easyui-linkbutton button-line-blue" data-options="iconCls:'icon-reload'">刷新</a>
    </div>  
 
	<!-- 点击工具栏弹出的编辑和创建window -->
	<div id="create_and_edit_deptinfo_win"></div>
	<!-- 点击工具栏弹出的增加员工window -->
	<div id="add_emp_to_dept_win"></div>
	<!-- 点击工具栏弹出的部门详情window -->
	<div id="dept_details_win"></div>
</body>
</html>